<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>前台子账号列表</title>
    <link rel="stylesheet" type="text/css" th:href="@{/manager/easyui/themes/default/easyui.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/manager/easyui/themes/icon.css}">
    <script type="text/javascript" th:src="@{/manager/easyui/jquery.min.js}"></script>
    <script type="text/javascript" th:src="@{/manager/easyui/jquery.easyui.min.js}"></script>
	<script type="text/javascript">
	   $(function(){
	       $('#userlist').datagrid({  
      				title:'前台用户列表',  
      				iconCls:'icon-save',
                    queryParams:{
                        "name": null,
                        "phone": null,
                        "wechat": null,
                        "qq": null,
                        "type": -1,
                        "companyid": sessionStorage.getItem("USER_COMPANY_ID")
                    },
                    url:"/manager/user/findAll",
      				columns:[
                          [
                					       {field:'name',title:'姓名',width:100,align:'center'},  
                					       {field:'phone',title:'电话',width:100,align:'center'},  
                					       {field:'wechat',title:'微信号',width:100,align:'center'},
                                 {field:'qq',title:'QQ',width:200,align:'center'},
                                 {field:'flag',title:'状态',width:100,align:'center',formatter:function (val,row){
                                         return val === 1?"启用":"禁用";
                                     }},
                                 {field:'cz',title:'操作',width:200,align:'center',formatter:function(val,row){
                                       return "<a href='javascript:showDg();'>查看</a>";
                                 }}
                          ]
                    ],
      				toolbar: "#tooldiv",  
      				pagination: true,
      				singleSelect:true
			});


          
          //初始化修改窗口  
         $('#dg').dialog({
  			    title: '用户详情',
  			    width: 700,
  			    height: 700,
  			    closed: true,
  			    cache: false,
  			    modal: true,
  			    iconCls: 'icon-save'
  			});

         //初始化绑定界面
         $("#addsub").dialog({
            title: '子账号绑定',
            width: 300,
            height: 200,
            closed: true,
            cache: false,
            modal: true,
            iconCls: 'icon-save',
            buttons: [{
                    text:'提交',
                    iconCls:'icon-ok',
                    handler:function(){
                        if($("#addsub input.easyui-textbox:eq(0)").textbox("getValue").trim() !== ""){
                            $.ajax({
                                dataType: "json",
                                url: "/manager/user/add",
                                data: {
                                    "phone": $("#addsub input.easyui-textbox:eq(0)").textbox("getValue"),
                                    "companyid": sessionStorage.getItem("USER_COMPANY_ID"),
                                },
                                success: function (result) {
                                    if (result.status == 200) {
                                        alert(result.msg);
                                        $("#userlist").datagrid('reload');
                                        $('#addsub').dialog('close');
                                    }else{
                                        alert(result.msg);
                                    }
                                },
                                error: function (xhr, status, error) {
                                    alert("请求失败: " + xhr.responseText); // 处理 AJAX 请求错误
                                }
                            });
                        }else{
                            alert("绑定手机内容不能为空!")
                        }
                    }
                },{
                    text:'关闭',
                    handler:function(){
                        $('#addsub').dialog("close");
                    }
                }]
        });

         //初始化查询按钮
         $("#submit_search").linkbutton({ iconCls: 'icon-search', plain: true })
            .click(function () {
                const tooldiv = document.getElementById('tooldiv');
                const inputs = tooldiv.querySelectorAll('input[type="text"]');
                var pager = $('#userlist').datagrid('getPager');
                // 直接设置数据网格的查询参数
                var queryParams = {
                    "page": 1,
                    "name": inputs[0].value,
                    "phone": inputs[1].value,
                    "wechat": inputs[2].value,
                    "qq": inputs[3] ? inputs[3].value : "",
                    "type": -1,
                    "companyid": sessionStorage.getItem("USER_COMPANY_ID")
                };
                $('#userlist').datagrid('options').queryParams = queryParams;
                $('#userlist').datagrid('reload');
                pager.pagination('refresh', {
                    pageNumber: 1
                });
            });
            
	   });

        //查询弹出方法
       function showDg(){
          $('#dg').dialog("open");
       }

       //打开绑定子账号界面
       function openaddsub(){
         $('#addsub').dialog("open");
       }

       function showConfirm(){
           var selectedRow = $("#userlist").datagrid('getSelected');
           if(selectedRow){
               var userConfirmed = confirm("确认是否解除关联?");
               if (userConfirmed) {
                   // 用户点击了确定按钮
                   $.ajax({
                       dataType: "json",
                       url: "/manager/user/modifyCompanyId",
                       data: {"id":selectedRow.id},
                       success: function (result) {
                           $('#userlist').datagrid('reload');
                       },
                       error: function (xhr, status, error) {
                           alert("请求失败: " + xhr.responseText); // 处理 AJAX 请求错误
                       }
                   });
               }
           }else{
                alert("请选中列表中对应的信息!");
           }
       }
	</script>
</head>
<body>
  <div id="tooldiv">
      <input type="text"  placeholder="请输入查询用户名"/>
      <input type="text"  placeholder="请输入查询电话"/>
      <input type="text"  placeholder="请输入查询微信"/>
      <input type="text"  placeholder="请输入查询QQ"/>
      <a id="submit_search">搜索</a>
      <a  class="easyui-linkbutton" data-options="iconCls:'icon-remove'" onclick="showConfirm()">解除关联</a>
      <a  class="easyui-linkbutton" data-options="iconCls:'icon-add'" onclick="openaddsub();">绑定子账号</a>
  </div>
  <table id="userlist"></table>
    <!--关联子账号详情界面-->
    <div id="dg">
           <div align="center" style="margin-top: 30px">
            <div style="margin-bottom:20px">
             <img src="./images/tx.jpg" alt="" style="width: 150px; height:150px;" />
            </div> 
            <div style="margin-bottom:20px">
                <input class="easyui-textbox"  style="width:50%" data-options="label:'姓名:'" readonly="true" value="张三" />
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox"  style="width:50%" data-options="label:'昵称:'" readonly="true" value="服务商员工1"/>
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox"  style="width:50%" data-options="label:'电话:'" readonly="true" value="123456"/>
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox"  style="width:50%;" data-options="label:'微信号:'" readonly="true" value="11111111111"/>
            </div> 
            <div style="margin-bottom:20px">
                <input class="easyui-textbox"  style="width:50%;" data-options="label:'QQ:'" readonly="true" value="2222222222"/>
            </div> 
            <div style="margin-bottom:20px">
                <input class="easyui-textbox"  style="width:50%;" data-options="label:'性别:'" readonly="true" value="男"/>
            </div> 
             <div style="margin-bottom:20px">
                <input class="easyui-textbox"  style="width:50%;" data-options="label:'注册时间:'" readonly="true" value="2021-1-1"/>
            </div> 
             <div style="margin-bottom:20px">
                <input class="easyui-textbox"  style="width:50%;" data-options="label:'状态:'" readonly="true" value="启用"/>
            </div> 
        </div>
   </div>
   <!--子账号添加界面-->
   <div id="addsub">
         <div align="center" style="margin-top: 30px">
            <div style="margin-bottom:20px">
                <input class="easyui-textbox"  style="width:80%" data-options="label:'绑定手机:'"/>
            </div>
         </div>
   </div>
</body>
</html>